<template>
  <div class="app-container">
    <el-form :ref="formName" :model="formFieldsData" :rules="rules">
      <el-form-item label="公众号名称：" :label-width="formLabelWidth" prop="name">
        <el-input type="text" v-model="formFieldsData.name" style="width: 60%"></el-input>
        <span class="tips">* 如：ecmoban</span>
      </el-form-item>
      <el-form-item label="公众号原始id：" :label-width="formLabelWidth" prop="ghid">
        <el-input type="text" v-model="formFieldsData.ghid" style="width: 60%"></el-input>
        <span class="tips">* 请认真填写，如：gh_845581623321</span>
      </el-form-item>
      <el-form-item label="AppID：" :label-width="formLabelWidth" prop="appid">
        <el-input type="text" v-model="formFieldsData.appid" style="width: 92%"></el-input>
        <p class="status_text">* AppID 请注意需要与微信公众号平台保持一致，且注意信息安全，不要随意透露给第三方</p>
      </el-form-item>
      <el-form-item label="AppSecret：" :label-width="formLabelWidth" prop="appSecret">
        <el-input type="text" v-model="formFieldsData.appSecret" style="width: 92%"></el-input>
        <p class="status_text">* AppSecret密钥需要与微信公众号平台保持一致，没有特别原因不要随意修改，也不要随意透露给第三方</p>
      </el-form-item>
      <el-form-item label="Token：" :label-width="formLabelWidth" prop="token">
        <el-input type="text" v-model="formFieldsData.token" style="width: 50%"></el-input>
        <span class="tips">* 自定义的Token值</span>
        <el-button type="success" class="btn">生成Token</el-button>
        <el-button type="primary" class="btn">复制Token</el-button>
      </el-form-item>
      <el-form-item label="EncodingAESKey：" :label-width="formLabelWidth" prop="name">
        <el-input type="text" v-model="formFieldsData.encodingAESKey" style="width: 40%"></el-input>
        <span class="tips">(选填) 由开发者手动填写或随机生成，将用作消息体加解密密钥</span>
      </el-form-item>
      <el-form-item label="状态：" :label-width="formLabelWidth" prop="status">
        <el-radio-group v-model="formFieldsData.status">
          <el-radio label="1">开启</el-radio>
          <el-radio label="2">关闭</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="微信URL接口地址：" :label-width="formLabelWidth" prop="url">
        <el-input type="text" v-model="formFieldsData.url" style="width: 80%"></el-input>
        <el-button type="primary" class="btn1">复制Url</el-button>
      </el-form-item>
      <el-button type="danger" @click="save">保存</el-button>
    </el-form>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import { parseTime } from '@/utils'
export default {
  mixins: [formOperate],
  data() {
    return {
      url: 'wechat/official/users',
      formName:'gzhSetting',
      formFieldsData: {
        name:'',
        ghid:'',
        appid:'',
        appSecret:'',
        token:'',
        status:'',
        encodingAESKey:'',
        url:''
      },
      formLabelWidth:'150px',
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入公众号名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
        ],
        ghid: [
          { required: true, message: '请输入公众号原始id', trigger: 'blur' }
        ],
        appid: [
          { required: true, message: '请输入AppID', trigger: 'blur' }
        ],
        appSecret: [
          { required: true, message: '请输入appSecret', trigger: 'blur'  }
        ],
        token: [
          { required: true, message: '请输入token', trigger: 'blur' }
        ],
        encodingAESKey: [
          { required: true, message: '请输入encodingAESKey', trigger: 'blur' }
        ],
        url: [
          { required: true, message: '请输入微信URL接口地址', trigger: 'blur' }
        ],
      },
    }
  },
  methods: {
    save() {
      this.$refs['gzhSetting'].validate(valid => {
        if (valid) {
          // this.$http.put('user/profile', this.user).then(response => {
          //   store.dispatch('user/getInfo').then(response => {
          //     const { roles, permissions } = response
          //     store.dispatch('permission/generateRoutes', [roles, permissions]).then(r => {})
          //   })
          //   this.$message.success(response.message)
          // })
        }
      })
    }
  }
}
</script>

<style scoped>
  .app-container{
    width: 800px;
  }
  .status_text{
    font-size: 12px;
    color:#777;
  }
  .tips{
    font-size: 12px;
    color:#777;
    margin-left: 10px;
  }
  .btn{
    margin-left: 10px;
    padding:9px 5px;
  }
  .btn1{
    margin-left: 10px;
  }
</style>
